package com.bestcem.xm.user.service.dto.setting;

import com.bestcem.bp.xm.user.grpc.v1.services.UnsubscribeSetting;
import com.bestcem.xm.common.core.uitls.GrpcDateUtil;
import com.bestcem.xm.user.controller.vo.GetUnsubscribeSettingVO;
import com.bestcem.xm.user.entity.pojo.UnsubscribeSettingDO;
import com.bestcem.xm.user.enums.UnsubscribeTypeEnum;
import lombok.Data;

import java.util.Date;
import java.util.Objects;

/**
 * 获取退订设置DTO
 *
 * @author ympan <yuming.pan@idiaoyan.com>
 * @version v1.0
 * @date 2022/7/12 18:03
 */
@Data
public class UnsubscribeSettingDTO {
    /**
     * 主键
     */
    private String id;

    /**
     * 公司id
     */
    private String orgId;

    /**
     * 退订类型，1:期限退订，2:永久退订
     *
     * @see UnsubscribeTypeEnum
     */
    private Integer type;

    /**
     * 持续时间，单位天，仅期限退订时设置
     */
    private Integer duration;

    /**
     * 创建用户id
     */
    private String creatorId;

    /**
     * 更新用户id
     */
    private String operatorId;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * UnsubscribeSettingDO to GetUnsubscribeSettingVO
     *
     * @param unsubscribeSettingDO 退订设置DO
     * @return 退订设置VO
     * @author ympan <yuming.pan@idiaoyan.com>
     * @date 18:06 2022/7/12
     */
    public static UnsubscribeSettingDTO do2Dto(UnsubscribeSettingDO unsubscribeSettingDO) {
        if (Objects.isNull(unsubscribeSettingDO)) {
            return null;
        }
        UnsubscribeSettingDTO unsubscribeSettingDTO = new UnsubscribeSettingDTO();
        unsubscribeSettingDTO.setId(unsubscribeSettingDO.getId());
        unsubscribeSettingDTO.setOrgId(unsubscribeSettingDO.getOrgId());
        unsubscribeSettingDTO.setType(unsubscribeSettingDO.getType());
        unsubscribeSettingDTO.setDuration(unsubscribeSettingDO.getDuration());
        unsubscribeSettingDTO.setCreatorId(unsubscribeSettingDO.getCreatorId());
        unsubscribeSettingDTO.setOperatorId(unsubscribeSettingDO.getOperatorId());
        unsubscribeSettingDTO.setCreateTime(unsubscribeSettingDO.getCreateTime());
        unsubscribeSettingDTO.setUpdateTime(unsubscribeSettingDO.getUpdateTime());
        return unsubscribeSettingDTO;
    }

    /**
     * UnsubscribeSettingDTO to GetUnsubscribeSettingVO
     *
     * @param unsubscribeSettingDTO 退订设置DTO
     * @return 退订设置VO
     * @author ympan <yuming.pan@idiaoyan.com>
     * @date 11:13 2022/7/14
     */
    public static GetUnsubscribeSettingVO dto2Vo(UnsubscribeSettingDTO unsubscribeSettingDTO) {
        if (Objects.isNull(unsubscribeSettingDTO)) {
            return null;
        }
        GetUnsubscribeSettingVO getUnsubscribeSettingVO = new GetUnsubscribeSettingVO();
        getUnsubscribeSettingVO.setId(unsubscribeSettingDTO.getId());
        getUnsubscribeSettingVO.setOrgId(unsubscribeSettingDTO.getOrgId());
        getUnsubscribeSettingVO.setType(unsubscribeSettingDTO.getType());
        getUnsubscribeSettingVO.setDuration(unsubscribeSettingDTO.getDuration());
        getUnsubscribeSettingVO.setCreatorId(unsubscribeSettingDTO.getCreatorId());
        getUnsubscribeSettingVO.setOperatorId(unsubscribeSettingDTO.getOperatorId());
        getUnsubscribeSettingVO.setCreateTime(unsubscribeSettingDTO.getCreateTime());
        getUnsubscribeSettingVO.setUpdateTime(unsubscribeSettingDTO.getUpdateTime());
        return getUnsubscribeSettingVO;
    }

    /**
     * unsubscribeSettingDTO to UnsubscribeSetting
     *
     * @param unsubscribeSettingDTO 退订设置DTO
     * @return 退订设置Msg
     * @author ympan <yuming.pan@idiaoyan.com>
     * @date 11:14 2022/7/14
     */
    public static UnsubscribeSetting dto2Msg(UnsubscribeSettingDTO unsubscribeSettingDTO) {
        if (Objects.isNull(unsubscribeSettingDTO)) {
            return null;
        }
        UnsubscribeSetting.Builder builder = UnsubscribeSetting.newBuilder();
        if (Objects.nonNull(unsubscribeSettingDTO.getId())) {
            builder.setId(unsubscribeSettingDTO.getId());
        }
        if (Objects.nonNull(unsubscribeSettingDTO.getOrgId())) {
            builder.setOrgId(unsubscribeSettingDTO.getOrgId());
        }
        if (Objects.nonNull(unsubscribeSettingDTO.getType())) {
            builder.setTypeValue(unsubscribeSettingDTO.getType());
        }
        if (Objects.nonNull(unsubscribeSettingDTO.getCreateTime())) {
            builder.setCreateTime(GrpcDateUtil.getTimestamp(unsubscribeSettingDTO.getCreateTime()));
        }
        if (Objects.nonNull(unsubscribeSettingDTO.getUpdateTime())) {
            builder.setUpdateTime(GrpcDateUtil.getTimestamp(unsubscribeSettingDTO.getUpdateTime()));
        }
        if (Objects.nonNull(unsubscribeSettingDTO.getDuration())) {
            builder.setDuration(unsubscribeSettingDTO.getDuration());
        }
        if (Objects.nonNull(unsubscribeSettingDTO.getCreatorId())) {
            builder.setCreatorId(unsubscribeSettingDTO.getCreatorId());
        }
        if (Objects.nonNull(unsubscribeSettingDTO.getOperatorId())) {
            builder.setOperatorId(unsubscribeSettingDTO.getOperatorId());
        }
        return builder.build();
    }
}
    